﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GtsServer.Manage.Controller;
using GtsServer.Model;
using GtsServer.Common;

namespace GtsServer.Manage.IISPage.Ajax
{
    /// <summary>
    /// LotteryPoolAjax 的摘要说明
    /// </summary>
    public class LotteryPoolAjax : IHttpHandler
    {

        LotteryPoolController controller = new LotteryPoolController();
        public void ProcessRequest(HttpContext context)
        {
            string type = string.Empty;
            if (context.Request["action"] != null)
            {
                type = context.Request["action"];

                switch (type)
                {
                    case "GetList":
                        GetList(context);
                        break;
                    case "Update":
                        Update(context);
                        break;
                    default:
                        break;
                }
            }
        }

        private void Update(HttpContext context)
        {
            // id: id, name: name, poolNum: poolNum, editTime: editTime, editNum: editNum, poolBet: poolBet },
            int id = Convert.ToInt32(context.Request["id"]);
            string name = context.Request["name"];
            int poolNum = Convert.ToInt32(context.Request["poolNum"]);
            int editTime = Convert.ToInt32(context.Request["editTime"]);
            int editNum = Convert.ToInt32(context.Request["editNum"]);
            int poolBet = Convert.ToInt32(context.Request["poolBet"]);
            bool isOpen = Convert.ToBoolean(context.Request["isOpen"]);
            string remark = context.Request["remark"];

            LotteryPool model = new LotteryPool()
            {
                ID = id,
                Name = name,
                EditNum = editNum,
                EditTime = editTime,
                PoolBet = poolBet,
                PoolNum = poolNum,
                IsOpen = isOpen,
                Remark = remark
            };

            context.Response.Write(controller.Update(model));
        }

        private void GetList(HttpContext context)
        {
            string json = JsonHelper.ListToJson<LotteryPool>(controller.GetList());
            context.Response.Write(json);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}